﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VectorDraw.Professional.vdPrimaries;
using VectorDraw.Professional.vdFigures;
using System.Windows.Forms;

namespace PDNPAS
{
    public class CustomClasses
    {
    }

    public class Land
    {
        int ID;//需要根据数据库修改
        string landID;  //
        int landPropID;
        double landArea;
        double areaCheckCoef=1.0;//地块面积校验系数
        double landLoadH;
        double landLoadL;
        double landLoadM;
        int loopstID;
        int flagID;
        string remark = "";
        int dFlag = 1;
        //vdPolyhatch hatch = new vdPolyhatch();
        MyHatch myhatch = new MyHatch();
        string landProp;
        int landColor;
        int planNum;
        string planName;
        string planLocation;
        double plotRatio;
        double loadDensityH;
        double loadDensityL;
        double simultaneity;
        double secSimultaneity;

        public Land(int landPropIDP, double landAreaP, MyHatch myhatchP, string landPropP, int landColorP,
            int planNumP, double plotRatioP, double loadDensityHP, double loadDensityLP, double simultaneityP, double secSimultaneityP)
        {
            this.landPropID = landPropIDP;
            this.landArea = landAreaP;
            this.myhatch = myhatchP;
            this.landProp = landPropP;
            this.landColor = landColorP;
            this.planNum = planNumP;
            this.plotRatio = plotRatioP;
            this.loadDensityH = loadDensityHP;
            this.loadDensityL = loadDensityLP;
            this.simultaneity = simultaneityP;
            this.SecSimultaneity = secSimultaneityP;
        }

        public Land() { }

        public int LID
        {
            get { return ID; }
            set { ID = value; }
        }
        public string LandID
        {
            get { return landID; }
            set { landID = value; }
        }
        public int LandPropID
        {
            get { return landPropID; }
            set { landPropID = value; }
        }
        public double LandArea
        {
            get { return landArea; }
            set { landArea = value; }
        }
        public double AreaCheckCoef
        {
            get { return areaCheckCoef; }
            set { areaCheckCoef = value; }
        }
        public double LandLoadH
        {
            get { return landLoadH; }
            set { landLoadH = value; }
        }
        public double LandLoadL
        {
            get { return landLoadL; }
            set { landLoadL = value; }
        }
        public double LandLoadM
        {
            get { return landLoadM; }
            set { landLoadM = value; }
        }
        public int LoopstID
        {
            get { return loopstID; }
            set { loopstID = value; }
        }
        public int FlagID
        {
            get { return flagID; }
            set { flagID = value; }
        }
        public string Remark
        {
            get
            {
                return remark;
            }
            set
            {
                remark = value;
            }
        }
        public int DFlag
        {
            get
            {
                return dFlag;
            }
            set
            {
                dFlag = value;
            }
        }
        public MyHatch Myhatch
        {
            get { return myhatch; }
            set { myhatch = value; }
        }

        public string LandProp
        {
            get { return landProp; }
            set { landProp = value; }
        }

        public int LandColor
        {
            get { return landColor; }
            set { landColor = value; }
        }

        public int PlanNum
        {
            get { return planNum; }
            set { planNum = value; }
        }
        public string PlanName
        {
            get { return planName; }
            set { planName = value; }
        }
        public string PlanLocation
        {
            get { return planLocation; }
            set { planLocation = value; }
        }
        public double PlotRatio
        {
            get { return plotRatio; }
            set { plotRatio = value; }
        }
        public double LoadDensityH
        {
            get { return loadDensityH; }
            set { loadDensityH = value; }
        }
        public double LoadDensityL
        {
            get { return loadDensityL; }
            set { loadDensityL = value; }
        }
        public double Simultaneity
        {
            get { return simultaneity; }
            set { simultaneity = value; }
        }

        public double SecSimultaneity
        {
            get { return secSimultaneity; }
            set { secSimultaneity = value; }
        }

        public void calculateLoad()
        {
            this.landLoadH = this.landArea * this.plotRatio * this.loadDensityH;
            this.landLoadL = this.landArea * this.plotRatio * this.loadDensityL;
            this.landLoadM = simultaneity * (this.landLoadH + this.landLoadL) / 2.00000;
        }

        public Land myClone()
        {
            Land cloneLand = new Land();
            cloneLand.landPropID = this.landPropID;
            cloneLand.landProp = this.landProp;
            cloneLand.landColor = this.landColor;
            cloneLand.landArea = this.landArea;
            cloneLand.plotRatio = this.plotRatio;
            cloneLand.loadDensityH = this.loadDensityH;
            cloneLand.loadDensityL = this.loadDensityL;
            cloneLand.simultaneity = simultaneity;
            cloneLand.secSimultaneity = this.secSimultaneity;
            cloneLand.LandLoadH = this.LandLoadH;
            cloneLand.LandLoadL = this.LandLoadL;
            cloneLand.LandLoadM = this.LandLoadM;

            return cloneLand;

        }

    }

    public class MyHatch : vdPolyhatch
    {
        vdPolyhatch hatch = new vdPolyhatch();

        public MyHatch() { }

        public MyHatch(vdPolyhatch hatchP)
        {
            this.hatch = hatchP;
        }

        public vdPolyhatch Hatch
        {
            get { return hatch; }
            set { hatch = value; }
        }

        public int getColorIndex()
        {
            if (this.hatch.HatchProperties.FillColor.ByBlock == true) //Then gets the pencolor of the hatch
            {
                if (this.hatch.PenColor.ByLayer == true) // Then gets the color of the layer
                    return (int)this.hatch.Layer.PenColor.ColorIndex;
                else
                    return (int)this.hatch.PenColor.ColorIndex;
            }
            else
            {
                if (this.hatch.HatchProperties.FillColor.ByLayer == true)
                    return (int)this.hatch.Layer.PenColor.ColorIndex;
                else
                    return (int)this.hatch.HatchProperties.FillColor.ColorIndex;
            }
        }
    }

    public class MyPLine : vdPolyline
    {
        vdPolyline pline = new vdPolyline();

        public MyPLine() { }

        public MyPLine(vdPolyline plineP)
        {
            this.pline = plineP;
        }

        public vdPolyline Pline
        {
            get { return pline; }
            set { pline = value; }
        }

        public int getColorIndex()
        {
            if (this.pline.HatchProperties.FillColor.ByBlock == true) //Then gets the pencolor of the pline
            {
                if (this.pline.PenColor.ByLayer == true) // Then gets the color of the layer
                    return (int)this.pline.Layer.PenColor.ColorIndex;
                else
                    return (int)this.pline.PenColor.ColorIndex;
            }
            else
            {
                if (this.pline.HatchProperties.FillColor.ByLayer == true)
                    return (int)this.pline.Layer.PenColor.ColorIndex;
                else
                    return (int)this.pline.HatchProperties.FillColor.ColorIndex;
            }
        }
    }

    //public class LayerWithHatches
    //{
    //    vdLayer layer;
    //    List<vdHatchPattern> hatchList= new List<vdHatchPattern>();
    //    int insideFlag = 0;
    //    public LayerWithHatches(vdLayer layerP, List<vdHatchPattern> hatchListP, int insideFlagP)
    //    {
    //        this.layer = layerP;
    //        this.hatchList = hatchListP;
    //        this.insideFlag = insideFlagP;
    //    }
    //    public LayerWithHatches(vdLayer layerP)
    //    {
    //        this.layer = layerP;
    //    }

    //    public vdLayer Layer
    //    {
    //        get { return layer; }
    //        set { layer = value; }
    //    }
    //    public List<vdHatchPattern> HatchList
    //    {
    //        get { return hatchList; }
    //        set { hatchList = value; } 
    //    }
    //    public int InsideFlag
    //    {
    //        get { return insideFlag; }
    //        set { insideFlag = value; }
    //    }
    //}

    public class User
    {
        int ID;//需要根据数据库修改      
        char[] userID = new char[8];
        string userName;
        string password;
        int authLevel;
        string authName;
        string remark = "";
        int dFlag = 1;

        public int UID
        {
            get { return ID; }
            set { ID = value; }
        }
        public char[] UserID
        {
            get { return userID; }
            set { userID = value; }
        }
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        public int AuthLevel
        {
            get { return authLevel; }
            set { authLevel = value; }
        }
        public string AuthName
        {
            get { return authName; }
            set { authName = value; }
        }
        public string Remark
        {
            get { return remark; }
            set { remark = value; }
        }
        public int DFlag
        {
            get { return dFlag; }
            set { dFlag = value; }
        }

        public User() { }
        public User(char[] userIDP, string userNameP, string passwordP, int authLevelP, string authNameP)
        {
            this.userID = userIDP;
            this.userName = userNameP;
            this.password = passwordP;
            this.authLevel = authLevelP;
            this.authName = authNameP;
        }

    }

    public class CADFile
    {
        int cadFileID;
        string fileName;
        string fileLocation;
        string planningArea;
        string remark;
        int dFlag;

        public int CADFileID
        {
            get { return cadFileID; }
            set { cadFileID = value; }
        }
        public string FileName
        {
            get { return fileName; }
            set { fileName = value; }
        }
        public string FileLocation
        {
            get { return fileLocation; }
            set { fileLocation = value; }
        }
        public string PlanningArea
        {
            get { return planningArea; }
            set { planningArea = value; }
        }
        public string Remark
        {
            get { return remark; }
            set { remark = value; }
        }
        public int DFlag
        {
            get { return dFlag; }
            set { dFlag = value; }
        }

        public CADFile() { }
        public CADFile(string fileNameP, string fileLocationP, string planningAreaP)
        {
            this.fileName = fileNameP;
            this.fileLocation = fileLocationP;
            this.planningArea = planningAreaP;
        }
        

    }

    public class PlanFlag
    { 
        int flagID;
        int uID;
        int cadFileID;
        DateTime storeTime;
        string remark;
        int dFlag;

        public int FlagID
        {
            get { return flagID; }
            set { flagID = value; }
        }
        public int UID
        {
            get { return uID; }
            set { uID = value; }
        }
        public int CADFileID
        {
            get { return cadFileID; }
            set { cadFileID = value; }
        }
        public DateTime StoreTime
        {
            get { return storeTime; }
            set { storeTime = value; }
        }
        public string Remark
        {
            get { return remark; }
            set {  remark = value; }
        }
        public int DFlag
        {
            get { return dFlag; }
            set { dFlag = value; }
        }

        public PlanFlag() { }
        public PlanFlag(int uIDP, int cadFileIDP, DateTime storeTimeP) 
        {
            this.uID = uIDP;
            this.cadFileID = cadFileIDP;
            this.storeTime = storeTimeP;
        }
    }

    public class Loopstation
    {
        int loopstID;
        string loopstName;
        double loopstX;
        double loopstY;
        //这里保留一个CAD中的一个对象。
        vdBlock blkSubstation = new vdBlock();
        vdInsert insSubstation = new vdInsert();

        List<Land> landList = new List<Land>();
        string loopstType;//用于价格估算，该种类型的取值最好从预先定义的enum中取。
        int voltageLevel;//10kv
        double load;
        double capacity;
        int standardUnitTID;//标准单元表编号
        int flagID;
        string remark="";
        int dFlag=1;
        int controlNum;

        public int LoopstID
        {
            get { return loopstID; }
            set { loopstID = value; }
        }
        public string LoopstName
        {
            get { return loopstName; }
            set { loopstName = value; }
        }
        public double LoopstX
        {
            get { return loopstX; }
            set { loopstX = value; }
        }
        public double LoopstY
        {
            get { return loopstY; }
            set { loopstY = value; }
        }

        public List<Land> LandList
        {
            get { return landList; }
            set { landList = value; }
        }
        public string LoopstType
        {
            get { return loopstType; }
            set { loopstType = value; }
        }
        public int VoltageLevel
        {
            get { return voltageLevel; }
            set { voltageLevel = value; }
        }
        public double Load
        {
            get { return load; }
            set { load = value; }
        }
        public double Capacity
        {
            get { return capacity; }
            set { capacity = value; }
        }
        public int StandardUnitTID
        {
            get { return standardUnitTID; }
            set { standardUnitTID = value; }
        }
        public int FlagID
        {
            get { return flagID; }
            set { flagID = value; }
        }
        public string Remark
        {
            get { return remark; }
            set { remark = value; }
        }
        public int DFlag
        {
            get { return dFlag; }
            set { dFlag = value; }
        }
        public int ControlNum
        {
            get { return controlNum; }
            set { controlNum = value; }
        }

        public Loopstation() { }
        public Loopstation(string loopstNameP, double loopstXP, double loopstYP, 
            string loopstTypeP, int voltageLevelP, double loadP, double capacityP)
        {
            this.loopstName = loopstNameP;
            this.loopstX = loopstXP;
            this.loopstY = loopstYP;
            this.loopstType = loopstTypeP;
            this.voltageLevel = voltageLevelP;
            this.load = loadP;
            this.capacity = capacityP;
        }

        public double GetLoad()
        {
            double load=0.0;
            for (int i = 0; i < landList.Count; i++)
            {
                load += landList[i].LandLoadM;
            }
            return load;
        }
    }

    public class Substation
    { 
        int substID;
        string substName;
        string substType="";
        double substX;
        double substY;
        int iVoltageLevel;
        int oVoltageLevel;
        int transfNum;
        double capacity;
        double load=0.0;
        int intervalNum;
        int flagID;
        string remark = "";
        int dFlag = 1;
        int controlNum;
        vdBlock blkSubstation = new vdBlock();
        vdInsert insSubstation = new vdInsert();

        public Substation () { }
        public Substation(string substNameP, double substXP,double substYP,
            int iVoltageLevelP,int oVoltageLevelP,vdBlock blkSubstationP,vdInsert insSubstationP)
        {
            substName = substNameP;
            substX = substXP;
            substY = substYP;
            iVoltageLevel = iVoltageLevelP;
            oVoltageLevel = oVoltageLevelP;
            blkSubstation = blkSubstationP;
            insSubstation = insSubstationP;
        }

        public int SubstID
        {
            get { return substID; }
            set { substID = value; }
        }
        public string SubstName
        {
            get { return substName; }
            set { substName = value; }
        }
        public string SubstType
        {
            get { return substType; }
            set { substType = value; }
        }
        public double SubstX
        {
            get { return substX; }
            set { substX = value; }
        }
        public double SubstY
        {
            get { return substY; }
            set { substY = value; }
        }
        public int IVoltageLevel
        {
            get { return iVoltageLevel; }
            set { iVoltageLevel = value; }
        }
        public int OVoltageLevel
        {
            get { return oVoltageLevel; }
            set { oVoltageLevel = value; }
        }
        public int TransfNum
        {
            get { return transfNum; }
            set { transfNum = value; }
        }
        public double Capacity
        {
            get { return capacity; }
            set { capacity = value; }
        }
        public double Load
        {
            get { return load; }
            set { load = value; }
        }
        public int IntervalNum
        {
            get { return intervalNum; }
            set { intervalNum = value; }
        }
        public int FlagID
        {
            get { return flagID; }
            set { flagID = value; }
        }
        public string Remark
        {
            get { return remark; }
            set { remark = value; }
        }
        public int DFlag
        {
            get { return dFlag; }
            set { dFlag = value; }
        }
        public int ControlNum
        {
            get{ return controlNum; }
            set { controlNum = value; }
        }
        public vdBlock BlkSubstation
        {
            get { return blkSubstation; }
            set { blkSubstation = value; }
        }
        public vdInsert InsSubstation
        {
            get { return insSubstation; }
            set{ insSubstation=value;}
        }
        /// <summary>
        /// 获取变电站的最大供电半径
        /// </summary>
        /// <param name="translineList"></param>
        /// <returns></returns>
        public double GetSupplyRadius(List<Transline> translineList)
        {
            double length = 0.0;
            if (translineList.Count == 0)
            {
                return length;
            }

            List<Transline> myLineList = new List<Transline>();
            for (int i = 0; i < translineList.Count; i++)
            {
                Transline line=translineList[i];
                if (line.StartP == this.ControlNum || line.EndP == this.ControlNum)
                {
                    myLineList.Add(line);
                }
            }


            for (int i = 0; i < myLineList.Count; i++)
            {
                char[] translineID = myLineList[i].TranslineID;
                string s1 = translineID[0].ToString() + translineID[1].ToString() + translineID[2].ToString();
                int standarUnitID = int.Parse(s1);
                string s2 = translineID[3].ToString() + translineID[4].ToString() + translineID[5].ToString();
                if (s2 == "001")
                {
                    if (Contains(translineList, s1 + "011") != null && Contains(translineList, s1 + "111") != null && Contains(translineList, s1 + "112") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "011").TranslineLen + Contains(translineList, s1 + "111").TranslineLen + Contains(translineList, s1 + "112").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }
                    if (Contains(translineList, s1 + "012") != null && Contains(translineList, s1 + "121") != null && Contains(translineList, s1 + "122") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "012").TranslineLen + Contains(translineList, s1 + "121").TranslineLen + Contains(translineList, s1 + "122").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }    
                }
                else if (s2 == "002")
                {
                    if (Contains(translineList, s1 + "021") != null && Contains(translineList, s1 + "211") != null && Contains(translineList, s1 + "212") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "021").TranslineLen + Contains(translineList, s1 + "211").TranslineLen + Contains(translineList, s1 + "212").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }
                    if (Contains(translineList, s1 + "022") != null && Contains(translineList, s1 + "221") != null && Contains(translineList, s1 + "222") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "022").TranslineLen + Contains(translineList, s1 + "221").TranslineLen + Contains(translineList, s1 + "222").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }  
                }
                else if (s2 == "003")
                {
                    if (Contains(translineList, s1 + "031") != null && Contains(translineList, s1 + "311") != null && Contains(translineList, s1 + "312") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "031").TranslineLen + Contains(translineList, s1 + "311").TranslineLen + Contains(translineList, s1 + "312").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }
                    if (Contains(translineList, s1 + "032") != null && Contains(translineList, s1 + "321") != null && Contains(translineList, s1 + "322") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "032").TranslineLen + Contains(translineList, s1 + "321").TranslineLen + Contains(translineList, s1 + "322").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }    
                }
                else if (s2 == "004")
                {
                    if (Contains(translineList, s1 + "041") != null && Contains(translineList, s1 + "411") != null && Contains(translineList, s1 + "412") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "041").TranslineLen + Contains(translineList, s1 + "411").TranslineLen + Contains(translineList, s1 + "412").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    }
                    if (Contains(translineList, s1 + "042") != null && Contains(translineList, s1 + "421") != null && Contains(translineList, s1 + "422") != null)
                    {
                        double lengthTemp = Contains(translineList, s1 + "042").TranslineLen + Contains(translineList, s1 + "421").TranslineLen + Contains(translineList, s1 + "422").TranslineLen + myLineList[i].TranslineLen;
                        if (lengthTemp > length)
                            length = lengthTemp;
                    } 
                }
                else { }


            }
            

            return length;
        }

        public Transline Contains(List<Transline> lineList, string lineID)
        {
            for (int i = 0; i < lineList.Count; i++)
            {
                if (new string(lineList[i].TranslineID) == lineID)
                    return lineList[i];

            }
            return null;
        }
    }

    public class SwitchStation
    { 
        int switchStID;
        string switchStName;
        double switchStX;
        double switchStY;
        string switchStType;
        int voltageLevel;
        double load;
        double capacity;
        int standardUnitTID;
        int flagID;//标记某一文件与时间
        string remark="";
        int dFlag = 1;//标记记录是否被删除
        int controlNum;//所有站点的总编号

        public int SwitchStID
        {
            get { return switchStID; }
            set { switchStID = value; }
        }
        public string SwitchStName
        {
            get
            {
                return switchStName;
            }
            set
            {
                switchStName = value;
            }
        }
        public double SwitchStX
        {
            get
            {
                return switchStX;
            }
            set
            {
                if (switchStX == value)
                    return;
                switchStX = value;
            }
        }
        public double SwitchStY
        {
            get
            {
                return switchStY;
            }
            set
            {
                if (switchStY == value)
                    return;
                switchStY = value;
            }
        }
        public string SwitchStType
        {
            get
            {
                return switchStType;
            }
            set
            {
                if (switchStType == value)
                    return;
                switchStType = value;
            }
        }
        public int VoltageLevel
        {
            get
            {
                return voltageLevel;
            }
            set
            {
                if (voltageLevel == value)
                    return;
                voltageLevel = value;
            }
        }
        public double Load
        {
            get
            {
                return load;
            }
            set
            {
                if (load == value)
                    return;
                load = value;
            }
        }
        public double Capacity
        {
            get
            {
                return capacity;
            }
            set
            {
                if (capacity == value)
                    return;
                capacity = value;
            }
        }
        public int StandardUnitTID
        {
            get
            {
                return standardUnitTID;
            }
            set
            {
                if (standardUnitTID == value)
                    return;
                standardUnitTID = value;
            }
        }
        public int FlagID
        {
            get
            {
                return flagID;
            }
            set
            {
                if (flagID == value)
                    return;
                flagID = value;
            }
        }
        public string Remark
        {
            get
            {
                return remark;
            }
            set
            {
                if (remark == value)
                    return;
                remark = value;
            }
        }
        public int DFlag
        {
            get
            {
                return dFlag;
            }
            set
            {
                if (dFlag == value)
                    return;
                dFlag = value;
            }
        }
        public int ControlNum
        {
            get { return controlNum; }
            set { controlNum = value; }
        }

        public SwitchStation() { }
        public SwitchStation(double switchStXP, double switchStYP, string switchStTypeP, int voltageLevelP, double loadP, 
            double capacityP)         
        {
            this.switchStX = switchStXP;
            this.switchStY = switchStYP;
            this.switchStType = switchStTypeP;
            this.voltageLevel = voltageLevelP;
            this.load = loadP;
            this.capacity = capacityP;
        }
    
    }

    public class Transline
    { 
        int ID;//数据库编号
        char[] translineID = new char[6];//线路编号，6位
        int translineTypeID;
        double translineLen;
        int startP;//所有站点的总编号
        int endP;
        double load;
        int standardUnitID;
        int flagID;
        string remark = "";
        int dFlag = 1;

        vdPolyline pline = new vdPolyline();

        string translineType;
        int voltageLevel;
        double capacity;

        public int TID
        {
            get { return ID; }
            set { ID = value; }
        }
        public char[] TranslineID
        {
            get { return translineID; }
            set { translineID = value; }
        }
        public int TranslineTypeID
        {
            get
            {
                return translineTypeID;
            }
            set
            {
                translineTypeID = value;
            }
        }
        public double TranslineLen
        {
            get
            {
                return translineLen;
            }
            set
            {
                translineLen = value;
            }
        }
        public int StartP
        {
            get
            {
                return startP;
            }
            set
            {
                startP = value;
            }
        }
        public int EndP
        {
            get
            {
                return endP;
            }
            set
            {
                endP = value;
            }
        }
        public double Load
        {
            get
            {
                return load;
            }
            set
            {
                load = value;
            }
        }
        public int StandardUnitID
        {
            get
            {
                return standardUnitID;
            }
            set
            {
                standardUnitID = value;
            }
        }
        public int FlagID
        {
            get
            {
                return flagID;
            }
            set
            {
                flagID = value;
            }
        }
        public string Remark
        {
            get
            {
                return remark;
            }
            set
            {
                remark = value;
            }
        }
        public int DFlag
        {
            get
            {
                return dFlag;
            }
            set
            {
                dFlag = value;
            }
        }
        public vdPolyline Pline
        {
            get { return pline; }
            set { pline = value; }
        }
        public string TranslineType
        {
            get
            {
                return translineType;
            }
            set
            {
                translineType = value;
            }
        }
        public int VoltageLevel
        {
            get
            {
                return voltageLevel;
            }
            set
            {
                voltageLevel = value;
            }
        }
        public double Capacity
        {
            get
            {
                return capacity;
            }
            set
            {
                capacity = value;
            }
        }

        public double GetSupplyRadius(List<Transline> translineList)
        {
            double length = 0.0;
            if (translineList.Count == 0)
            {
                return length;
            }

            char[] translineID = this.TranslineID;
            string s1 = translineID[0].ToString() + translineID[1].ToString() + translineID[2].ToString();
            int standarUnitID = int.Parse(s1);
            string s2 = translineID[3].ToString() + translineID[4].ToString() + translineID[5].ToString();
            if (s2 == "001")
            {
                if (Contains(translineList, s1 + "011") != null && Contains(translineList, s1 + "111") != null && Contains(translineList, s1 + "112") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "011").TranslineLen + Contains(translineList, s1 + "111").TranslineLen + Contains(translineList, s1 + "112").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
                if (Contains(translineList, s1 + "012") != null && Contains(translineList, s1 + "121") != null && Contains(translineList, s1 + "122") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "012").TranslineLen + Contains(translineList, s1 + "121").TranslineLen + Contains(translineList, s1 + "122").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
            }
            else if (s2 == "002")
            {
                if (Contains(translineList, s1 + "021") != null && Contains(translineList, s1 + "211") != null && Contains(translineList, s1 + "212") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "021").TranslineLen + Contains(translineList, s1 + "211").TranslineLen + Contains(translineList, s1 + "212").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
                if (Contains(translineList, s1 + "022") != null && Contains(translineList, s1 + "221") != null && Contains(translineList, s1 + "222") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "022").TranslineLen + Contains(translineList, s1 + "221").TranslineLen + Contains(translineList, s1 + "222").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
            }
            else if (s2 == "003")
            {
                if (Contains(translineList, s1 + "031") != null && Contains(translineList, s1 + "311") != null && Contains(translineList, s1 + "312") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "031").TranslineLen + Contains(translineList, s1 + "311").TranslineLen + Contains(translineList, s1 + "312").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
                if (Contains(translineList, s1 + "032") != null && Contains(translineList, s1 + "321") != null && Contains(translineList, s1 + "322") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "032").TranslineLen + Contains(translineList, s1 + "321").TranslineLen + Contains(translineList, s1 + "322").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
            }
            else if (s2 == "004")
            {
                if (Contains(translineList, s1 + "041") != null && Contains(translineList, s1 + "411") != null && Contains(translineList, s1 + "412") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "041").TranslineLen + Contains(translineList, s1 + "411").TranslineLen + Contains(translineList, s1 + "412").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
                if (Contains(translineList, s1 + "042") != null && Contains(translineList, s1 + "421") != null && Contains(translineList, s1 + "422") != null)
                {
                    double lengthTemp = Contains(translineList, s1 + "042").TranslineLen + Contains(translineList, s1 + "421").TranslineLen + Contains(translineList, s1 + "422").TranslineLen;
                    if (lengthTemp > length)
                        length = lengthTemp;
                }
            }
            else { }
            return length;
        }
        public Transline Contains(List<Transline> lineList, string lineID)
        {
            for (int i = 0; i < lineList.Count; i++)
            {
                if (new string(lineList[i].TranslineID) == lineID)
                    return lineList[i];

            }
            return null;
        }

    }

    public class StandardUnit
    { 
        int ID;
        int standardUnitID;
        List<Substation> substationList = new List<Substation>();
        List<SwitchStation> switchstationList = new List<SwitchStation>();
        List<Loopstation> loopstationList = new List<Loopstation>();
        List<Land> landList = new List<Land>();
        List<Transline> translineList = new List<Transline>();

        public int SID
        {
            get { return ID; }
            set { ID = value; }
        }
        public int StandardUnitID
        {
            get
            {
                return standardUnitID;
            }
            set
            {
                standardUnitID = value;
            }
        }
        public List<Substation> SubStationList
        {
            get { return substationList; }
            set
            {
            	substationList = value;
            }
        }
        public List<SwitchStation> SwitchstationList
        {
            get { return switchstationList; }
            set { switchstationList = value; }
        }
        public List<Loopstation> LoopstationList
        {
            get { return loopstationList; }
            set { loopstationList = value; }
        }
        public List<Land> LandList
        {
            get { return landList; }
            set { landList = value; }
        }
        public List<Transline> TranslineList
        {
            get { return translineList; }
            set { translineList = value; }
        }

        public double GetLoad()
        { 
            double load=0.0;
            for (int i = 0; i < loopstationList.Count; i++)
            {
                load += loopstationList[i].Load;
            }
            return load;        
        }
    }

    public class SupplyArea  //供区类
    {
        List<Land> landList = new List<Land>();
        List<Loopstation> loopstationList = new List<Loopstation>();//供区的环网单元

        public List<Land> LandList
        {
            get { return landList; }
            set { landList = value; }
        }
        public List<Loopstation> LoopstationList
        {
            get { return loopstationList; }
            set { loopstationList = value; }
        }


    }

    enum LineTypes : int { YJV22_3_300, JKLYJ_10_185, VLV22 };

}